package com.rcloud.stock.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.rcloud.stock.R;

import java.util.ArrayList;

public class ViewRecyclerAdapter extends RecyclerView.Adapter<ViewRecyclerAdapter.ViewHolder> {

    private final Context context;
    private final DetailZxRecyclerAdapter zxRecyclerAdapter;
    private final DetailGgRecyclerAdapter ggRecyclerAdapter;
    public ViewRecyclerAdapter(Context context, DetailZxRecyclerAdapter zxRecyclerAdapter,DetailGgRecyclerAdapter ggRecyclerAdapter){
        this.context = context;
        this.ggRecyclerAdapter = ggRecyclerAdapter;
        this.zxRecyclerAdapter = zxRecyclerAdapter;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view  = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_detail_zx,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        switch (position){
            case 0:
                holder.recyclerView.setAdapter(this.zxRecyclerAdapter);
                break;
            case 1:
                holder.recyclerView.setAdapter(this.ggRecyclerAdapter);
                break;
        }
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(context));
//        holder.recyclerView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
//        holder.recyclerView.setNestedScrollingEnabled(false);
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        public RecyclerView recyclerView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            recyclerView = itemView.findViewById(R.id.zxRecyclerView);
        }
    }
}